package com.zhuojy.equity.mall.admin.service.car;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuojy.equity.mall.admin.common.entity.po.car.TCarFuelCardReleasePO;
import com.zhuojy.equity.mall.admin.common.pojo.ResultEntity;
import com.zhuojy.equity.mall.admin.dal.mapper.car.TCarFuelcardMapper;
import com.zhuojy.equity.mall.admin.dal.mapper.car.TCarFuelcardReleaseMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author xrz
 * @version 1.0
 * @description:TODO
 * @date 2024/4/1 20:49
 */
@Slf4j
@Service
@RequiredArgsConstructor

public class TCarFuelcardReleaseService extends ServiceImpl<TCarFuelcardReleaseMapper,TCarFuelCardReleasePO> {
    @Autowired
    private TCarFuelcardMapper tCarFuelcardMapper;
    public ResultEntity findcarfuelcardrelease(TCarFuelCardReleasePO TCarFuelCardReleasePO, Integer pageSize, Integer pageNum,Integer type) {
        Page<TCarFuelCardReleasePO> page = new Page<>(pageNum, pageSize);
        IPage<TCarFuelCardReleasePO> tCarPage = this.baseMapper.findcarfuelcardrelease(TCarFuelCardReleasePO, page,type);
        return ResultEntity.OK(tCarPage);
    }

    public ResultEntity delById(Integer id) {
        this.baseMapper.deleteById(id);
        return ResultEntity.OK("删除成功");
    }


    public ResultEntity addtCarFuelCardRelease(TCarFuelCardReleasePO tCarFuelCardReleasePO) {
        if (tCarFuelCardReleasePO.getType()==0){
            tCarFuelcardMapper.updateMoneyById(tCarFuelCardReleasePO.getFuelcardName(),tCarFuelCardReleasePO.getReleaseAmount());
        }else {
            tCarFuelcardMapper.updateMoneyById2(tCarFuelCardReleasePO.getFuelcardName(),tCarFuelCardReleasePO.getReleaseAmount());
        }

        this.baseMapper.insert(tCarFuelCardReleasePO);
        return ResultEntity.OK("添加成功");
    }
}
